package com.example.product.proxy;

import java.lang.reflect.Proxy;

public class DynamicProxy {

    public static<T> T newProxyInstance(Class<T> target) {

        Object o = Proxy.newProxyInstance(target.getClassLoader(),
                target.getInterfaces(), (proxy, method, args) -> {
                    System.out.println(target.getInterfaces());
                    System.out.println("newProxyInstance:" + proxy.getClass() + ",method:" + method.getName() + ",args:" + args);
                    return method.invoke(target.getConstructor().newInstance(), args);
                });
        return (T) o;
    }
}
